package com.neuedu.his.mapper;

import com.neuedu.his.po.Constantitem;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * 针对表【constantitem】的数据库操作Mapper
 */
public interface ConstantitemMapper extends BaseMapper<Constantitem> {

    // 逻辑删除(将DelMark设置为0)
    @Update("UPDATE constantitem SET DelMark = 0 WHERE ID = #{id}")
    int deleteByIdLogical(@Param("id") Integer id);

    // 根据ID更新全部字段
    @Update("UPDATE constantitem SET " +
            "ConstantTypeID = #{constanttypeid}, " +
            "ConstantCode = #{constantcode}, " +
            "ConstantName = #{constantname}, " +
            "DelMark = #{delmark} " +
            "WHERE ID = #{id}")
    int updateAllFieldsById(Constantitem entity);

    // 查询所有未删除的常数项(DelMark=1)
    @Select("SELECT * FROM constantitem WHERE DelMark = 1")
    List<Constantitem> findAllActiveItems();

    // 新增：根据常数项编码查询单个记录（未删除）
    @Select("SELECT * FROM constantitem WHERE ConstantCode = #{code} AND DelMark = 1")
    Constantitem findByConstantCode(@Param("code") String code);
}